import requests
from bs4 import BeautifulSoup

headers = {'user-agent': 'Mozilla/5.0 (Windows NT 5.2; U; en; rv:1.8.1) Gecko/20061208 Firefox/2.0.0 Opera 9.50'}


def hot():
    # 知乎热榜50
    # id = 9
    url = 'https://www.zhihu.com/api/v3/feed/topstory/hot-lists/total?limit=50&desktop=true'
    headers.update({'x-api-version': '3.0.76'})
    response = requests.get(url, headers=headers).json()
    data = []
    for each in response['data']:
        data.append([each['target']['title_area']['text'], each['target']['link']['url']])
    return str(data)


def get_daily():
    # 知乎日报
    # id = 10
    url = 'https://daily.zhihu.com'
    response = requests.get(url, headers=headers).text
    soup = BeautifulSoup(response, 'lxml')
    titles = soup.find_all('span', class_='title')
    urls = soup.find_all('a', class_='link-button')
    result = []
    for i in range(len(titles)):
        info = [titles[i].text, url + urls[i].get('href')]
        result.append(info)
    return str(result)


if __name__ == '__main__':
    a = get_hot()
    print(a)
